package com.example.client.web;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.Tracer;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * 降级
 * 2024/12/11 14:51
 *
 * @author chenjh
 */
@RestController
public class DegradeController {

    //正常请求 http://127.0.0.1:8081/demo2Annotation?name=lisi
    //异常请求 http://127.0.0.1:8081/demo2Annotation?name=error
    @RequestMapping("/demo2Annotation")
    @ResponseBody
    public String demo2Annotation(@RequestParam(name = "name", defaultValue = "unknown user") String name) {
        if ("error".equals(name)) {
            throw new RuntimeException("error");
        }
        return "Hello " + name;
    }
}
